package cn.iocoder.an.module.mold.service.upkeepstatics;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.an.module.mold.controller.admin.upkeepstatics.vo.*;
import cn.iocoder.an.module.mold.dal.dataobject.upkeepstatics.UpkeepStaticsDO;
import cn.iocoder.an.framework.common.pojo.PageResult;
import cn.iocoder.an.framework.common.pojo.PageParam;
import cn.iocoder.an.framework.common.util.object.BeanUtils;

import cn.iocoder.an.module.mold.dal.mysql.upkeepstatics.UpkeepStaticsMapper;

import static cn.iocoder.an.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.an.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.an.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.an.module.mold.enums.ErrorCodeConstants.*;

/**
 * 保养统计 Service 实现类
 *
 * @author 超级管理员
 */
@Service
@Validated
public class UpkeepStaticsServiceImpl implements UpkeepStaticsService {

    @Resource
    private UpkeepStaticsMapper upkeepStaticsMapper;

    @Override
    public Long createUpkeepStatics(UpkeepStaticsSaveReqVO createReqVO) {
        // 插入
        UpkeepStaticsDO upkeepStatics = BeanUtils.toBean(createReqVO, UpkeepStaticsDO.class);
        upkeepStaticsMapper.insert(upkeepStatics);

        // 返回
        return upkeepStatics.getId();
    }

    @Override
    public void updateUpkeepStatics(UpkeepStaticsSaveReqVO updateReqVO) {
        // 校验存在
        validateUpkeepStaticsExists(updateReqVO.getId());
        // 更新
        UpkeepStaticsDO updateObj = BeanUtils.toBean(updateReqVO, UpkeepStaticsDO.class);
        upkeepStaticsMapper.updateById(updateObj);
    }

    @Override
    public void deleteUpkeepStatics(Long id) {
        // 校验存在
        validateUpkeepStaticsExists(id);
        // 删除
        upkeepStaticsMapper.deleteById(id);
    }

    @Override
        public void deleteUpkeepStaticsListByIds(List<Long> ids) {
        // 删除
        upkeepStaticsMapper.deleteByIds(ids);
        }


    private void validateUpkeepStaticsExists(Long id) {
        if (upkeepStaticsMapper.selectById(id) == null) {
            throw exception(UPKEEP_STATICS_NOT_EXISTS);
        }
    }

    @Override
    public UpkeepStaticsDO getUpkeepStatics(Long id) {
        return upkeepStaticsMapper.selectById(id);
    }

    @Override
    public PageResult<UpkeepStaticsDO> getUpkeepStaticsPage(UpkeepStaticsPageReqVO pageReqVO) {
        return upkeepStaticsMapper.selectPage(pageReqVO);
    }

}